package org.darkforest.common.util;

import java.util.List;

/**
 * 项目名称 :bwmall-common 文件名 :PageVo.java 开发公司及作者 :陈超 版本号及开发日期 :Rev. 1.00
 * (2015年2月1日)
 * add PIC_GALLERY_PAGE_SIZE by chenyu@2015-02-14
 */

public class Page<T> {

    private int start = 0;
    private int pageSize = 0;
    private int count = 0;
    private String sortColumn; //排序字段
    private Integer storeId;
    private Boolean  pageSwitch = true;
    private String sortType; //升序 降序？

    //是否是一对多关联分页查询？ start
    private boolean isQueryRelation = false;
    //是否是一对多关联分页查询？ end



    private int pageStart;              //分页数量超出10页之后 计算页面显示的起始以及结束页号，避免显示过多
    private int pageEnd;

    public static final int DEFAULT_PAGE_SIZE = 10;
    public static final int PIC_GALLERY_PAGE_SIZE = 9;      //商品图片gallery默认分页大小
    public static final int PIC_AJAX_PAGE_SIZE = 14;        //商品发布页面中ajax图片列表大小
    public static final int PIC_AJAX_GALLERY_SIZE = 12;        //商品发布页面3中ajax图片列表大小



    public boolean isQueryRelation() {
        return isQueryRelation;
    }

    public void setIsQueryRelation(boolean isQueryRelation) {
        this.isQueryRelation = isQueryRelation;
    }

    public Boolean getPageSwitch() {
        return pageSwitch;
    }

    public void setPageSwitch(Boolean pageSwitch) {
        this.pageSwitch = pageSwitch;
    }

    private List<T> resultList;

    public int getStart() {
        return start < 1 ? 1 : start;
    }

    public void setStart(int start) {
        this.start = start;
    }

    public int getPageSize() {
        return pageSize == 0 ? DEFAULT_PAGE_SIZE : pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public List<T> getResultList() {
        return resultList;
    }

    public void setResultList(List<T> resultList) {
        this.resultList = resultList;
    }

    public int getStartNumber() {
        return getStart() * getPageSize() - getPageSize();
    }

    public int getPageCount() {

//        if(!isQueryRelation()){
            return count / getPageSize() + (count % getPageSize() > 0 ? 1 : 0);

//        }else{
//            return count / getPageSize() + (count % getPageSize() > 0 ? 1 : 0) -1;
//
//        }

    }

    public int getCount() {
        return count;
    }

    public Integer getStoreId() {
        return storeId;
    }

    public void setStoreId(Integer storeId) {
        this.storeId = storeId;
    }

    public void setCount(int count) {
        this.count = count;
    }

    public int getPageStart() {
        return getStart()<5 ? 1 : getStart() -4;
    }

    public int getPageEnd() {
        return getStart() > this.getPageCount() - 5 ? getPageCount() : getStart()+5;
    }


    public String getSortType() {
        return sortType;
    }

    public void setSortType(String sortType) {
        this.sortType = sortType;
    }

    public String getSortColumn() {
        return sortColumn;
    }

    public void setSortColumn(String sortColumn) {
        this.sortColumn = sortColumn;
    }

    @Override
    public String toString() {
        return "Page{" +
                "start=" + start +
                ", pageSize=" + getPageSize() +
                ", count=" + count +
                '}';
    }
}
